package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.TArea;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IAreaDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: Stanley.Y
 * @Date: 2024/7/16
 * @Description:
 * @Version 1.0.0
 */

@RestController
@Anonymous
@RequestMapping("/system/area")
public class AreaDataController extends BaseController {
    @Autowired
    private IAreaDataService areaDataService;

    /**
     * 获取所有区域数据
     * @return
     */
    @GetMapping("/getAreaDataList")
    public AjaxResult getObstacleDataList(){
        return success(areaDataService.getAreaDataList());
    }

    /**
     * 获取区域数据列表
     */
    @PreAuthorize("@ss.hasPermi('basedata:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(TArea area) {
        startPage();
        List<TArea> list = areaDataService.selectAreaDataList(area);
        return getDataTable(list);
    }

    /**
     * 根据区域数据主键ID获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('basedata:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable String id) {
        TArea result = areaDataService.selectAreaDataById(id);
        return success(result);
    }

    /**
     * 新增区域数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:area:add')")
    @Log(title = "区域数据维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody TArea area) {
        area.setCreateTime(new Timestamp(System.currentTimeMillis()));
        return toAjax(areaDataService.insertAreaData(area));
    }

    /**
     * 修改区域数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:area:edit')")
    @Log(title = "区域数据维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody TArea area)
    {
        System.out.println("controller edit area ===: " + area);
        return toAjax(areaDataService.updateAreaData(area));
    }

    /**
     * 删除障碍物数据
     */
    @PreAuthorize("@ss.hasPermi('basedata:area:remove')")
    @Log(title = "区域数据维护", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(areaDataService.deleteAreaDataByIds(ids));
    }
}
